package com.tianji.promotion.config;


import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * @description
 * @author: ZXX-挚爱
 * @time: 2023/8/2 12:30
 */
@Configuration
@Slf4j
public class PromotionConfig {

    @Bean
    public Executor generateExchangeCodeExecutor(){
        log.info("spring线程池的创建及初始化");
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        //1.核心线程数大小
        //1.核心线程数大小
        executor.setCorePoolSize(2);
        //2.最大线程数大小
        executor.setMaxPoolSize(5);
        //3.队列大小
        executor.setQueueCapacity(200);
        //4.线程名字
        executor.setThreadNamePrefix("exchange-code-handler-");
        //5.拒绝策略
        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
        //6.初始化线程池
        executor.initialize();
        //7.返回线程池
        return  executor;

    }
}
